package com.wss.merchant.util;


import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class PlusAutoGenerator {
    public static void main(String[] args) {

        AutoGenerator autoGenerator = new AutoGenerator();
        //数据库
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDbType(DbType.MYSQL);
        dataSourceConfig.setUrl("jdbc:mysql://8.136.105.10:3306/live?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT");
        dataSourceConfig.setDriverName("com.mysql.cj.jdbc.Driver");


        dataSourceConfig.setUsername("live");
        dataSourceConfig.setPassword("8AjHJCM7r2remNFb");
        autoGenerator.setDataSource(dataSourceConfig);

        // 全局配置
        GlobalConfig globalConfig = new GlobalConfig();
            //生成的文件放到那个位置 项目目录
        globalConfig.setOutputDir(System.getProperty("user.dir")+"/src/main/java");
            //创建好的文件是否打开
        globalConfig.setOpen(false);
            //作者
        globalConfig.setAuthor("wss");
            //生成Service接口名称 去I
        globalConfig.setServiceName("%sService");
        autoGenerator.setGlobalConfig(globalConfig);

        //包配置
        PackageConfig packageConfig = new PackageConfig();
            //包的具体路径
        packageConfig.setParent("com.wss.merchant");
            //各种包名
        packageConfig.setController("controller");
        packageConfig.setService("service");
        packageConfig.setServiceImpl("service.impl");
        packageConfig.setMapper("mapper");
            //实体类包
        packageConfig.setEntity("domain");
        autoGenerator.setPackageInfo(packageConfig);

        //配置策略
        StrategyConfig strategyConfig = new StrategyConfig();
            //创建实体类自动添加Lombok注解
        strategyConfig .setEntityLombokModel(true);
            //生成指定表
        strategyConfig.setInclude("dl_new_shop_order_second");
            //把数据库中的下划线的字段改成驼峰命名
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
        strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);
        autoGenerator.setStrategy(strategyConfig);

        //启动
        autoGenerator.execute();
    }
}
